package yto.freemarker.springbootstudy.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yto.freemarker.springbootstudy.util.ZipUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Zip文件打包下载的案列
 * <p>
 * 前台：文件列表，选中文件，传文件ID集合传到后台
 *
 * @author dongxing
 * @create 2018-04-02 8:46
 **/
@RestController
@RequestMapping("/e")
public class ZipDownloadController {

    @GetMapping("/download/zip/1")
    public void getZipDownload(HttpServletRequest request, HttpServletResponse response) {

        //接受到文件ID集合，查询出文件urlList
//        List<AttachFile> attachFileList = bookService.findAttachFileList(ids);
        List<String> strFiles = new ArrayList<String>();
//        for (AttachFile attachFile : attachFileList) {
//            strFiles.add(attachFile.getAttachFileUrl());
//        }

        strFiles.add("d:/你好.txt");
        strFiles.add("d:/不好.txt");

        ZipUtil.ZipFiles(request,response,strFiles,"你好.zip");
    }
}
